﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SonCa.SocialNetwork.Profiles.IPresenters;
using System.ComponentModel.Composition;
using Core.Interfaces;
using Core.Common;
using Core.DataAccess;
using Core.BusinessLogic.Interfaces;

namespace SonCa.SocialNetwork.Profiles.Presenters
{
    public class ProfilePresenter
    {
        private IProfilePresenter _view;
        [Import]
        private IUserSession _userSession;
        [Import]
        private IAccountService _accountService;
        [Import]
        private IFriendService _friendService;
        [Import]
        private IStatusUpdateService _statusUpdateService;
        [Import]
        private IRedirector _redirector;

        private Core.DataAccess.Account _accountBeingViewed;

        public ProfilePresenter()
        {
            MEFManager.Compose(this);
        }

        public void Init(IProfilePresenter View, string username)
        {
            _view = View;
            if (string.IsNullOrEmpty(username))
                _accountBeingViewed = _userSession.CurrentUser;
            else
                _accountBeingViewed = _accountService.GetAccountByUsername(username);

            if (_accountBeingViewed != null)
            {
                _view.DisplayInfo(_accountBeingViewed);
                _view.SetAvatar(_accountBeingViewed.AccountID);
            }
            else
            {
                _redirector.GoToLoginPage();
            }
        }

    }
}